home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / dos / diverses / cexpress / keyboard / inpint.asm < prev    next >
Encoding:
Assembly Source File  |  1989-05-03  |  5.3 KB  |  170 lines

  1. ;void  input_integer(col,row,color,max_len,return_strg);
  2. ;  unsigned short  col,row,color,max_len;
  3. ;  char *return_strg;
  4.  
  5.     EXTRN  _memory_model:byte
  6.     EXTRN  _beep_on:byte
  7.  
  8. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  9.     ASSUME CS:_TEXT
  10.     PUBLIC _input_integer
  11. _input_integer proc near
  12.     push bp            ;
  13.     mov  bp,sp        ;set up stack frame
  14.     push di            ;
  15.     push si            ;
  16.     cmp  _memory_model,0    ;code near or far?
  17.     jle  begin        ;jump if near
  18.     inc  bp            ;else add 2 to BP
  19.     inc  bp            ;
  20. begin:  cmp  _memory_model,2    ;data near or far?
  21.     jb   A0            ;jump if near
  22.     les  si,dword ptr[bp+12] ;ES:SI pts to return strg
  23.     jmp  short A00        ;jump ahead
  24. A0:    mov  ax,ds        ;move DS to ES
  25.     mov  es,ax        ;
  26.     mov  si,[bp+12]        ;ES:SI pts to return strg
  27. A00:    mov  byte ptr es:[si],0    ;set NumStrg descriptor
  28.     mov  dl,[bp+4]        ;column in DL
  29.     dec  dl            ;count from 0
  30.     mov  dh,[bp+6]        ;row in DH
  31.     dec  dh            ;count from 0
  32.     sub  bh,bh        ;select page 0
  33.     mov  bl,[bp+8]        ;attribute in BL
  34.     mov  al,[bp+10]        ;MaxLen to AL
  35.     or   al,al        ;test for zero length
  36.     jnz  A1            ;jump if not zero
  37.     jmp  Q1            ;else quit routine
  38. A1:    sub  ah,ah        ;clear AH
  39.     mov  di,ax        ;store MaxLen in DI
  40.     sub  bp,bp        ;current length in BP
  41.     mov  ah,2        ;function to set cursor
  42.     int  10h        ;set cursor
  43. B1:    sub  ah,ah        ;func to read keystroke
  44.     int  16h        ;wait for keystroke
  45.     or   al,al        ;test for extended code
  46.     jnz  C1            ;jump if not extended
  47.     cmp  ah,83        ;is it the delete key?
  48.     jne  B1            ;next keystroke if not
  49.     jmp  J1            ;else jump to delete code
  50. C1:    cmp  al,8        ;is it the backspace?
  51.     jne  D1            ;jump ahead if not
  52.     jmp  J1            ;else go to delete code
  53. D1:    cmp  al,13        ;chk for carriage return
  54.     jne  E1            ;jump ahead if not
  55.     jmp  O1            ;else go to CR code
  56. E1:    cmp  al,'-'        ;chk for minus sign
  57.     jne  F1            ;jump ahead if not
  58.     or   bp,bp        ;current str len 0?
  59.     jnz  B1            ;new keystroke if not
  60.     inc  di            ;inc MaxLen counter
  61.     jmp  G1            ;go write it
  62. F1:    cmp  al,'0'        ;below '0' char?
  63.     jb   B1            ;get another keystroke
  64.     cmp  al,'9'        ;above '9' char?
  65.     ja   B1            ;get another keystroke
  66.     cmp  bp,di        ;cmp current/max length
  67.     jb   G1            ;jump ahead if not full
  68. F2:    push dx            ;keep cursor position
  69.     mov  ah,2        ;DOS func to write char
  70.     mov  dl,7        ;bell character
  71.     cmp  _beep_on,0        ;test whether beep enabled
  72.     je   F3            ;jump ahead if not
  73.     int  21h        ;beep!
  74. F3:    pop  dx            ;restore cursor position
  75.     jmp  short B1        ;go get another keystroke
  76. G1:    inc  bp            ;inc current length
  77.     cmp  bp,1        ;only 1 char?
  78.     je   I1            ;no char shift if so
  79.     push ax            ;save new keystroke
  80.     mov  cx,bp        ;current length to CX
  81.     dec  cx            ;count from 0
  82.     sub  dl,cl        ;shift curs to lft char+1
  83. H1:    inc  dl            ;cursor back 1 to right
  84.     mov  ah,2        ;func to set cursor
  85.     int  10h        ;set the cursor
  86.     mov  ah,8        ;func reads cursor char
  87.     int  10h        ;read the char
  88.     push ax            ;save char
  89.     dec  dl            ;shift cursor 1 col left
  90.     mov  ah,2        ;function to set cursor
  91.     int  10h        ;set the cursor
  92.     pop  ax            ;restore char
  93.     push cx            ;keep counter in CX
  94.     mov  ah,9        ;function to write char
  95.     mov  cx,1        ;number chars to write
  96.     int  10h        ;write the char
  97.     pop  cx            ;restore counter
  98.     inc  dl            ;cursor right 1 col
  99.     loop H1            ;go shift next
  100.     mov  ah,2        ;func to set cursor
  101.     int  10h        ;set the cursor
  102.     pop  ax            ;restore new keystroke
  103. I1:    mov  ah,9        ;function to write char
  104.     mov  cx,1        ;number chars to write
  105.     int  10h        ;write the char in AL    
  106.     mov  cl,1        ;increment value
  107.     add  es:[si],cl        ;inc NumStrg descriptor
  108.     mov  es:[bp][si],al    ;write char to NumStrg
  109.     jmp  B1            ;go get next keystroke
  110. J1:    or   bp,bp        ;DELETE: none to delete?
  111.     jnz  K1            ;jump ahead if not
  112.     jmp  F2            ;ignor, next keystroke
  113. K1:    push dx            ;save cursor position
  114.     dec  bp            ;dec current strg len
  115.     push bp            ;save current strg len
  116.     or   bp,bp        ;test for 0 len
  117.     jnz  M1            ;if not 0, shift chars
  118.     mov  al,'-'        ;1 char, test if '-'
  119.     cmp  es:[si+1],al    ;chk 1st char in string
  120.     jne  L1            ;jump ahead if not '-'
  121.     dec  di            ;else dec MaxLen ctr
  122. L1:    jmp  N1            ;skip char shift when 0
  123. M1:    dec  dl            ;move cursor 1 col left
  124.     mov  ah,2        ;function to set cursor
  125.     int  10h        ;set the cursor
  126.     mov  ah,8        ;func reads char at curs
  127.     int  10h        ;read the char
  128.     push ax            ;save the char
  129.     inc  dl            ;move cursor 1 col right
  130.     mov  ah,2        ;function to set cursor
  131.     int  10h        ;set the cursor
  132.     pop  ax            ;restore the char
  133.     mov  ah,9        ;func to write a char
  134.     int  10h        ;write the char
  135.     dec  dl            ;move cursor 1 col left
  136.     dec  bp            ;dec str len counter
  137.     cmp  bp,0        ;finished shifting chars?
  138.     jne  M1            ;loop if not
  139.     mov  ah,2        ;func to set cursor
  140.     int  10h        ;set the cursor
  141. N1:    mov  al,' '        ;write space char
  142.     mov  ah,9        ;function to write char
  143.     int  10h        ;erase leftmost char
  144.     pop  bp            ;restore current len
  145.     pop  dx            ;restore cursor position
  146.     mov  ah,2        ;func to set cursor
  147.     int  10h        ;set cursor
  148.     mov  cl,1        ;decrement value
  149.     sub  es:[si],cl        ;dec ret str descriptor
  150.     jmp  b1            ;go get next keystroke
  151. O1:    sub  cx,cx        ;convert to C string
  152.     mov  cl,es:[si]        ;get string length
  153.     or   cl,cl        ;test for zero length
  154.     jz   Q1            ;quit if null string
  155. P1:    mov  al,es:[si+1]    ;get a char
  156.     mov  es:[si],al        ;shift downward
  157.     inc  si            ;forward ptr
  158.     loop P1            ;move whole string
  159.     mov  byte ptr es:[si],0    ;terminating byte
  160. Q1:    pop  si            ;
  161.     pop  di            ;
  162.     pop  bp            ;
  163.     cmp  _memory_model,0    ;quit
  164.     jle  quit        ;
  165.     db   0CBh        ;RET far
  166. quit:    ret            ;RET near
  167. _input_integer ENDP
  168. _TEXT    ENDS
  169.     END
  170.